import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
var _excluded = ["page", "size"];

/**
 * model 调度日志
 * @date: 2018-9-3


 */
import { getResponse, createPagination } from 'utils/utils';
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { fetchLogsList as _fetchLogsList, deleteLogs as _deleteLogs, fetchErrorDetail as _fetchErrorDetail, fetchLogDetail as _fetchLogDetail, fetchProgress as _fetchProgress, clearLogs as _clearLogs } from "../services/jobLogService";
export default {
  namespace: 'jobLog',
  state: {
    groupsList: [],
    // 执行器列表
    jobsList: [],
    // 执行器任务列表
    jobLogList: [],
    // 列表数据
    clearTypeList: [],
    // 清理方式
    pagination: {},
    // 分页信息对象
    // addressTypeList: [], // 注册方式
    // logStatusList: [], // 任务状态
    jobResultList: [],
    // 调度结果
    clientResultList: [],
    // 客户端执行结果
    handleMsgData: {},
    // 执行日志
    query: {},
    // 查询参数
    skipQuery: {} // 从调度任务或者并发请求页面跳转过来时携带的参数

  },
  effects: {
    // 获取初始化数据
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_, _ref) {
      var call, put, jobLogMap, _jobLogMap$jobResultL, jobResultList, _jobLogMap$clientResu, clientResultList, _jobLogMap$clearTypeL, clearTypeList;

      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              call = _ref.call, put = _ref.put;
              _context.t0 = getResponse;
              _context.next = 4;
              return call(queryMapIdpValue, {
                clientResultList: 'CSDR.LOG.CLIENT_RESULT',
                jobResultList: 'CSDR.LOG.JOB_RESULT',
                clearTypeList: 'CSDR.JOB_LOG_CLEAR_TYPE'
              });

            case 4:
              _context.t1 = _context.sent;
              jobLogMap = (0, _context.t0)(_context.t1);
              _jobLogMap$jobResultL = jobLogMap.jobResultList, jobResultList = _jobLogMap$jobResultL === void 0 ? [] : _jobLogMap$jobResultL, _jobLogMap$clientResu = jobLogMap.clientResultList, clientResultList = _jobLogMap$clientResu === void 0 ? [] : _jobLogMap$clientResu, _jobLogMap$clearTypeL = jobLogMap.clearTypeList, clearTypeList = _jobLogMap$clearTypeL === void 0 ? [] : _jobLogMap$clearTypeL;
              _context.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  // addressTypeList,
                  // logStatusList,
                  // clearTypeList,
                  jobResultList: jobResultList,
                  clientResultList: clientResultList,
                  clearTypeList: clearTypeList
                }
              });

            case 9:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    fetchLogsList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchLogsList(_ref2, _ref3) {
      var payload, call, put, _payload$page, page, _payload$size, size, query, res, result;

      return _regeneratorRuntime.wrap(function fetchLogsList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref2.payload;
              call = _ref3.call, put = _ref3.put;
              _payload$page = payload.page, page = _payload$page === void 0 ? 0 : _payload$page, _payload$size = payload.size, size = _payload$size === void 0 ? 10 : _payload$size, query = _objectWithoutProperties(payload, _excluded);
              _context2.next = 5;
              return call(_fetchLogsList, _objectSpread({
                page: page,
                size: size
              }, query));

            case 5:
              res = _context2.sent;
              result = getResponse(res);

              if (!result) {
                _context2.next = 10;
                break;
              }

              _context2.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  query: query,
                  jobLogList: result.content,
                  pagination: createPagination(result)
                }
              });

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchLogsList);
    }),
    deleteLogs: /*#__PURE__*/_regeneratorRuntime.mark(function deleteLogs(_ref4, _ref5) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function deleteLogs$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              call = _ref5.call;
              _context3.next = 4;
              return call(_deleteLogs, _objectSpread({}, payload));

            case 4:
              result = _context3.sent;
              return _context3.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, deleteLogs);
    }),
    clearLogs: /*#__PURE__*/_regeneratorRuntime.mark(function clearLogs(_ref6, _ref7) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function clearLogs$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              call = _ref7.call;
              _context4.next = 4;
              return call(_clearLogs, _objectSpread({}, payload));

            case 4:
              result = _context4.sent;
              return _context4.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, clearLogs);
    }),
    // 获取错误详情
    fetchErrorDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchErrorDetail(_ref8, _ref9) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function fetchErrorDetail$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref8.payload;
              call = _ref9.call;
              _context5.next = 4;
              return call(_fetchErrorDetail, payload);

            case 4:
              result = _context5.sent;
              return _context5.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, fetchErrorDetail);
    }),
    // 获取错误详情
    fetchLogDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchLogDetail(_ref10, _ref11) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function fetchLogDetail$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref10.payload;
              call = _ref11.call;
              _context6.next = 4;
              return call(_fetchLogDetail, payload);

            case 4:
              result = _context6.sent;
              return _context6.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, fetchLogDetail);
    }),
    // 获取任务进度
    fetchProgress: /*#__PURE__*/_regeneratorRuntime.mark(function fetchProgress(_ref12, _ref13) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function fetchProgress$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              call = _ref13.call;
              _context7.next = 4;
              return call(_fetchProgress, payload);

            case 4:
              result = _context7.sent;
              return _context7.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, fetchProgress);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref14) {
      var payload = _ref14.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};